#include <stdio.h>
#include <stdlib.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrCoreCopy.h>
#include <flgrMorphoBaseSegment.h>
#include "../macro.h"

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_erode types
/////////////////////////////////////////////////////////////////////////
#define tstErodeLineHorizontal(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105, 28, 28, 28, 41, 41, 48, 54, 57, 62,		\
		  72, 72, 75, 75, 76, 75, 75, 75, 76, 76,		\
		  75, 75, 76, 76, 73, 71, 64, 62, 55, 55,		\
		  44, 42, 32, 32, 32,100, 88, 82, 73, 73,		\
		  73, 73, 76, 76, 81, 85, 86, 90, 90, 92,		\
		  91, 91, 96, 96, 96, 96, 97, 97, 97, 99,		\
		  96, 96, 96, 98, 93, 93, 93, 94, 94, 94,		\
		  90, 88, 87, 87, 87, 85, 85, 35,  5,  5};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_erode_line_horizontal(img,imgsrc,3);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1

  
int testerodeLineHorizontal_fgUINT8(void) {
  tstErodeLineHorizontal(fgUINT8);
}

int testerodeLineHorizontal_fgUINT16(void) {
  tstErodeLineHorizontal(fgUINT16);
}

int testerodeLineHorizontal_fgUINT32(void) {
  tstErodeLineHorizontal(fgUINT32);
}

int testerodeLineHorizontal_fgINT8(void) {
  tstErodeLineHorizontal(fgINT8);
}

int testerodeLineHorizontal_fgINT16(void) {
  tstErodeLineHorizontal(fgINT16);
}

int testerodeLineHorizontal_fgINT32(void) {
  tstErodeLineHorizontal(fgINT32);
}

int testerodeLineHorizontal_fgFLOAT32(void) {
  tstErodeLineHorizontal(fgFLOAT32);
}

int testerodeLineHorizontal_fgFLOAT64(void) {
  tstErodeLineHorizontal(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_dilate types
/////////////////////////////////////////////////////////////////////////
#define tstDilateLineHorizontal(dtype)				\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={115,115,115, 41, 48, 54, 57, 62, 70, 70,		\
		  76, 76, 76, 76, 78, 78, 78, 78, 78, 78,		\
		  79, 79, 79, 77, 77, 77, 73, 71, 64, 62,		\
		  50, 50, 44,123,123,123,112,100, 88, 82,		\
		  76, 76, 81, 85, 86, 90, 90, 93, 93, 93,		\
		  96, 96,100,100,100, 98, 98,102,102,102,		\
		  98, 99,102,102,102,100,100,100, 99, 96,		\
		  94, 94, 90, 88, 88, 88, 88, 87, 87, 35};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_dilate_line_horizontal(img,imgsrc,3);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  return 1


int testdilateLineHorizontal_fgUINT8(void) {
  tstDilateLineHorizontal(fgUINT8);
}
int testdilateLineHorizontal_fgUINT16(void) {
  tstDilateLineHorizontal(fgUINT16);
}
int testdilateLineHorizontal_fgUINT32(void) {
  tstDilateLineHorizontal(fgUINT32);
}
int testdilateLineHorizontal_fgINT8(void) {
  tstDilateLineHorizontal(fgINT8);
}
int testdilateLineHorizontal_fgINT16(void) {
  tstDilateLineHorizontal(fgINT16);
}
int testdilateLineHorizontal_fgINT32(void) {
  tstDilateLineHorizontal(fgINT32);
}
int testdilateLineHorizontal_fgFLOAT32(void) {
  tstDilateLineHorizontal(fgFLOAT32);
}
int testdilateLineHorizontal_fgFLOAT64(void) {
  tstDilateLineHorizontal(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_erode types
/////////////////////////////////////////////////////////////////////////
#define tstErodeRectangle(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 72, 28, 28, 28, 41, 41, 48, 54, 57, 62,		\
		   72, 28, 28, 28, 41, 41, 48, 54, 55, 55,		\
		   44, 42, 32, 32, 32, 71, 64, 62, 55, 55,		\
		   44, 42, 32, 32, 32, 71, 64, 62, 55, 55,		\
		   44, 42, 32, 32, 32, 85, 86, 82, 73, 73,		\
		   73, 73, 76, 76, 81, 85, 86, 90, 90, 92,		\
		   90, 88, 87, 87, 87, 85, 85, 35,  5,  5,		\
		   90, 88, 87, 87, 87, 85, 85, 35,  5,  5};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_erode_rectangle(img,imgsrc,3,3);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1

  
int testerodeRectangle_fgUINT8(void) {
  tstErodeRectangle(fgUINT8);
}

int testerodeRectangle_fgUINT16(void) {
  tstErodeRectangle(fgUINT16);
}

int testerodeRectangle_fgUINT32(void) {
  tstErodeRectangle(fgUINT32);
}

int testerodeRectangle_fgINT8(void) {
  tstErodeRectangle(fgINT8);
}

int testerodeRectangle_fgINT16(void) {
  tstErodeRectangle(fgINT16);
}

int testerodeRectangle_fgINT32(void) {
  tstErodeRectangle(fgINT32);
}

int testerodeRectangle_fgFLOAT32(void) {
  tstErodeRectangle(fgFLOAT32);
}

int testerodeRectangle_fgFLOAT64(void) {
  tstErodeRectangle(fgFLOAT64);
}




/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_dilate types
/////////////////////////////////////////////////////////////////////////
#define tstDilateRectangle(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={115,115,115, 76, 78, 78, 78, 78, 78, 78,		\
	 	  115,115,115, 77, 78, 78, 78, 78, 78, 78,		\
		  79, 79, 79,123,123,123,112,100, 88, 82,		\
		  79, 79, 81,123,123,123,112,100, 93, 93,		\
		  96, 96,100,123,123,123,112,102,102,102,		\
		  98, 99,102,102,102,100,100,102,102,102,		\
		  98, 99,102,102,102,100,100,102,102,102,		\
		  98, 99,102,102,102,100,100,100, 99, 96};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_dilate_rectangle(img,imgsrc,3,3);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1


int testdilateRectangle_fgUINT8(void) {
  tstDilateRectangle(fgUINT8);
}
int testdilateRectangle_fgUINT16(void) {
  tstDilateRectangle(fgUINT16);
}
int testdilateRectangle_fgUINT32(void) {
  tstDilateRectangle(fgUINT32);
}
int testdilateRectangle_fgINT8(void) {
  tstDilateRectangle(fgINT8);
}
int testdilateRectangle_fgINT16(void) {
  tstDilateRectangle(fgINT16);
}
int testdilateRectangle_fgINT32(void) {
  tstDilateRectangle(fgINT32);
}
int testdilateRectangle_fgFLOAT32(void) {
  tstDilateRectangle(fgFLOAT32);
}
int testdilateRectangle_fgFLOAT64(void) {
  tstDilateRectangle(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_open types
/////////////////////////////////////////////////////////////////////////
#define tstOpenRectangle(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 72, 72, 28, 41, 41, 48, 54, 57, 62, 62,		\
		   72, 72, 42, 41, 71, 71, 71, 64, 62, 62,		\
		   72, 72, 42, 41, 71, 71, 71, 64, 62, 55,		\
		   44, 44, 42, 32, 85, 86, 86, 86, 82, 73,		\
		   73, 76, 76, 81, 85, 86, 90, 90, 92, 92,		\
		   90, 90, 88, 87, 87, 87, 90, 90, 92, 92,		\
		   90, 90, 88, 87, 87, 87, 90, 90, 92, 92,		\
		   90, 90, 88, 87, 87, 87, 85, 85, 35,  5};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_open_rectangle(img,imgsrc,3,3);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1


int testopenRectangle_fgUINT8(void) {
  tstOpenRectangle(fgUINT8);
}
int testopenRectangle_fgUINT16(void) {
  tstOpenRectangle(fgUINT16);
}
int testopenRectangle_fgUINT32(void) {
  tstOpenRectangle(fgUINT32);
}
int testopenRectangle_fgINT8(void) {
  tstOpenRectangle(fgINT8);
}
int testopenRectangle_fgINT16(void) {
  tstOpenRectangle(fgINT16);
}
int testopenRectangle_fgINT32(void) {
  tstOpenRectangle(fgINT32);
}
int testopenRectangle_fgFLOAT32(void) {
  tstOpenRectangle(fgFLOAT32);
}
int testopenRectangle_fgFLOAT64(void) {
  tstOpenRectangle(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close types
/////////////////////////////////////////////////////////////////////////
#define tstCloseRectangle(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={115,115, 76, 76, 76, 78, 78, 78, 78, 78,		\
		  79, 79, 76, 76, 76, 78, 78, 78, 78, 78,		\
		  79, 79, 77, 77, 77, 78, 78, 78, 78, 78,		\
		  79, 79, 79, 79,123,112,100, 88, 82, 82,		\
		  79, 79, 79, 81,100,100,100, 93, 93, 93,		\
		  96, 96, 96,100,100,100,100,100,102,102,		\
		  98, 98, 99,102,100,100,100, 99, 96, 96,		\
		  98, 98, 99,102,100,100,100, 99, 96, 96};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_close_rectangle(img,imgsrc,3,3);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1


int testcloseRectangle_fgUINT8(void) {
  tstCloseRectangle(fgUINT8);
}
int testcloseRectangle_fgUINT16(void) {
  tstCloseRectangle(fgUINT16);
}
int testcloseRectangle_fgUINT32(void) {
  tstCloseRectangle(fgUINT32);
}
int testcloseRectangle_fgINT8(void) {
  tstCloseRectangle(fgINT8);
}
int testcloseRectangle_fgINT16(void) {
  tstCloseRectangle(fgINT16);
}
int testcloseRectangle_fgINT32(void) {
  tstCloseRectangle(fgINT32);
}
int testcloseRectangle_fgFLOAT32(void) {
  tstCloseRectangle(fgFLOAT32);
}
int testcloseRectangle_fgFLOAT64(void) {
  tstCloseRectangle(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_openTopHat types
/////////////////////////////////////////////////////////////////////////
#define tstOpenTopHatRectangle(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 33, 43,  0,  0,  0,  0,  0,  0,  0,  8,		\
		   0,  4, 33, 35,  5,  7,  4, 13, 16, 14,		\
		   3,  7, 35, 35,  6,  2,  0,  0,  0,  0,		\
		   6,  0,  0,  0, 38, 26, 14,  2,  0,  0,		\
		   0,  0,  0,  0,  0,  0,  0,  0,  1,  0,		\
		   1,  6,  8, 13,  9, 11,  8,  7, 10,  7,		\
		   8,  6, 11, 15, 11,  6, 10,  9,  2,  4,		\
		   4,  0,  0,  0,  1,  1,  0,  2,  0,  0};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_open_tophat_rectangle(img,imgsrc,3,3);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1


int testopenTopHatRectangle_fgUINT8(void) {
  tstOpenTopHatRectangle(fgUINT8);
}
int testopenTopHatRectangle_fgUINT16(void) {
  tstOpenTopHatRectangle(fgUINT16);
}
int testopenTopHatRectangle_fgUINT32(void) {
  tstOpenTopHatRectangle(fgUINT32);
}
int testopenTopHatRectangle_fgINT8(void) {
  tstOpenTopHatRectangle(fgINT8);
}
int testopenTopHatRectangle_fgINT16(void) {
  tstOpenTopHatRectangle(fgINT16);
}
int testopenTopHatRectangle_fgINT32(void) {
  tstOpenTopHatRectangle(fgINT32);
}
int testopenTopHatRectangle_fgFLOAT32(void) {
  tstOpenTopHatRectangle(fgFLOAT32);
}
int testopenTopHatRectangle_fgFLOAT64(void) {
  tstOpenTopHatRectangle(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_closeTopHat types
/////////////////////////////////////////////////////////////////////////
#define tstCloseTopHatRectangle(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 10,  0, 48, 35, 35, 30, 24, 21, 16,  8,		\
		   7,  3,  1,  0,  0,  0,  3,  1,  0,  2,		\
		   4,  0,  0,  1,  0,  5,  7, 14, 16, 23,		\
		   29, 35, 37, 47,  0,  0,  0,  0,  0,  9,		\
		   6,  3,  3,  0, 15, 14, 10,  3,  0,  1,		\
		   5,  0,  0,  0,  4,  2,  2,  3,  0,  3,		\
		   0,  2,  0,  0,  2,  7,  0,  0,  2,  0,		\
		   4,  8, 11, 15, 12, 12, 15, 12, 61, 91};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_close_tophat_rectangle(img,imgsrc,3,3);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1


int testcloseTopHatRectangle_fgUINT8(void) {
  tstCloseTopHatRectangle(fgUINT8);
}
int testcloseTopHatRectangle_fgUINT16(void) {
  tstCloseTopHatRectangle(fgUINT16);
}
int testcloseTopHatRectangle_fgUINT32(void) {
  tstCloseTopHatRectangle(fgUINT32);
}
int testcloseTopHatRectangle_fgINT8(void) {
  tstCloseTopHatRectangle(fgINT8);
}
int testcloseTopHatRectangle_fgINT16(void) {
  tstCloseTopHatRectangle(fgINT16);
}
int testcloseTopHatRectangle_fgINT32(void) {
  tstCloseTopHatRectangle(fgINT32);
}
int testcloseTopHatRectangle_fgFLOAT32(void) {
  tstCloseTopHatRectangle(fgFLOAT32);
}
int testcloseTopHatRectangle_fgFLOAT64(void) {
  tstCloseTopHatRectangle(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_dilate types
/////////////////////////////////////////////////////////////////////////
#define tstOpenLineHorizontal(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105,105, 28, 41, 41, 48, 54, 57, 62, 62,		\
		  72, 75, 75, 76, 76, 76, 75, 76, 76, 76,		\
		  75, 76, 76, 76, 76, 73, 71, 64, 62, 55,		\
		  44, 44, 42, 32,100,100,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 92, 92,		\
		  91, 96, 96, 96, 96, 97, 97, 97, 99, 99,		\
		  96, 96, 98, 98, 98, 93, 94, 94, 94, 94,		\
		  90, 90, 88, 87, 87, 87, 85, 85, 35,  5};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret = flgr2d_open_line_horizontal(img, imgsrc, 3);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1

int testopenLineHorizontal_fgUINT8(void) {
  tstOpenLineHorizontal(fgUINT8);
}
int testopenLineHorizontal_fgUINT16(void) {
  tstOpenLineHorizontal(fgUINT16);
}
int testopenLineHorizontal_fgUINT32(void) {
  tstOpenLineHorizontal(fgUINT32);
}
int testopenLineHorizontal_fgINT8(void) {
  tstOpenLineHorizontal(fgINT8);
}
int testopenLineHorizontal_fgINT16(void) {
  tstOpenLineHorizontal(fgINT16);
}
int testopenLineHorizontal_fgINT32(void) {
  tstOpenLineHorizontal(fgINT32);
}
int testopenLineHorizontal_fgFLOAT32(void) {
  tstOpenLineHorizontal(fgFLOAT32);
}
int testopenLineHorizontal_fgFLOAT64(void) {
  tstOpenLineHorizontal(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_dilate types
/////////////////////////////////////////////////////////////////////////
#define tstCloseLineHorizontal(dtype)				\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={115,115, 41, 41, 41, 48, 54, 57, 62, 70,		\
		  76, 76, 76, 76, 76, 78, 78, 78, 78, 78,		\
		  79, 79, 77, 77, 77, 73, 71, 64, 62, 62,		\
		  50, 44, 44, 44,123,112,100, 88, 82, 82,		\
		  76, 76, 76, 81, 85, 86, 90, 90, 93, 93,		\
		  96, 96, 96,100, 98, 98, 98, 98,102,102,		\
		  98, 98, 99,102,100,100,100, 99, 96, 96,		\
		  94, 90, 88, 88, 88, 88, 87, 87, 35, 35};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret = flgr2d_close_line_horizontal(img, imgsrc, 3);		\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1
	

int testcloseLineHorizontal_fgUINT8(void) {
  tstCloseLineHorizontal(fgUINT8);
}
int testcloseLineHorizontal_fgUINT16(void) {
  tstCloseLineHorizontal(fgUINT16);
}
int testcloseLineHorizontal_fgUINT32(void) {
  tstCloseLineHorizontal(fgUINT32);
}
int testcloseLineHorizontal_fgINT8(void) {
  tstCloseLineHorizontal(fgINT8);
}
int testcloseLineHorizontal_fgINT16(void) {
  tstCloseLineHorizontal(fgINT16);
}
int testcloseLineHorizontal_fgINT32(void) {
  tstCloseLineHorizontal(fgINT32);
}
int testcloseLineHorizontal_fgFLOAT32(void) {
  tstCloseLineHorizontal(fgFLOAT32);
}
int testcloseLineHorizontal_fgFLOAT64(void) {
  tstCloseLineHorizontal(fgFLOAT64);
}

